<template>
  <div>
    <van-nav-bar class="page-nav"
  title="个人信息"
  left-arrow
  right-text="完成"
  @click-left="$emit('close')"
  @click-right="onClickRight"
></van-nav-bar>
     <van-field
  v-model="message"
  rows="2"
  autosize
  type="textarea"
  maxlength="7"
  placeholder="请输入新的昵称"
  show-word-limit
/>
  </div>
</template>

<script>
import { changeUser } from '@/api/user.js'
export default {
  props: {
    value: {
      type: [Number, String],
      required: true
    }
  },
  data () {
    return {
      message: ''
    }
  },
  created () {
    this.message = this.value
  },
  methods: {
    async onClickRight () {
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        loadingType: 'spinner',
        duration: 0
      })
      try {
        if (this.message.trim() === '') return this.$toast('请输入昵称')
        await changeUser({
          name: this.message
        })
        this.$toast('修改成功')
        this.$emit('close')
        this.$emit('input', this.message)
      } catch (err) {
        this.$toast('修改失败', err)
      }
    }
  }
}
</script>

<style scoped lang="less">
/deep/.van-nav-bar__text {
  color: #fff;
}
</style>
